//分享操作
(function ($) {
    $.fn.share = function (options) {
        var settings = {
            shareUrl:"http://www.jiathis.com/send/?uid=92366",
            width:650,
            height:500,
            appkeys:{
                tsina:"2678308326",
                renren:"a34cc79178484dc1af7d05c176038355",
                tqq:"801152991",
                qzone:"100632343"
            }
        };
        if (options) {
            $.extend(settings, options);
        }
        /**
         * 设置分享参数
         * @param webid 分享标示
         * @param url 链接地址
         * @param title  标题
         * @param summary 摘要
         */
        var setparam = function (myUrl, webid, title, summary) {
            //居中处理 left top
            var windowWidth = document.documentElement.clientWidth;
            var windowHeight = document.documentElement.clientHeight;
            var top = (windowHeight - settings.height) / 2 + $(document).scrollTop();
            var left = (windowWidth - settings.width) / 2;
            var appkey = "";
            if (webid && title) {
                //传递过来的
            } else {
                //获取 title 和 url
                title = document.title;
            }
            //判断链接地址是否有
            if (myUrl) {
            } else {
                myUrl = window.location.href;
            }
            var url = settings.shareUrl + "&webid=" + webid + "&title=" + title
            if (webid == "tsina") {
                appkey = settings.appkeys.tsina;
            } else if (webid == "tqq") {
                appkey = settings.appkeys.tqq;
            } else if (webid == "renren") {
                appkey = settings.appkeys.renren;
            } else if (webid == "qzone") {
                appkey = settings.appkeys.qzone;
            }
            if (summary) {
                url = url + "&summary=" + summary;
            }
            if (appkey) {
                url = url + "&appkey=" + appkey;
            }
            if (myUrl) {
                url = url + "&url=" + myUrl;
            }
            window.open(url, '', 'width=' + settings.width + ', height=' + settings.height + ', top=' + top + ', left=' + left + ',' +
                ' toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no');

        }
        $(this).click(function () {
            var self = this;
            var webid = $(self).data("webid");
            var title = $(self).parent().data('title');
            var summary = $(self).parent().data('summary');
            var url = $(self).parent().data('url');
            setparam(url, webid, title, summary);
        });
    }
}(jQuery));